﻿using System;
using System.Collections.Generic;
using System.Text;
using DotNet.Common;
using DotNet.Data.Factory;
using System.Collections;
using System.Data;
using System.Data.SqlClient;
namespace DotNet.Data
{
	public class tab_caseDal
	{
		IDBHelp db = DBHelp.Create();
		 Hashtable htSyn = Hashtable.Synchronized(new Hashtable());
		StringBuilder strSql = new StringBuilder();

		#region 是否存在该记录
		/// <summary>
		/// 是否存在该记录
		/// </summary>
		/// <param name="cid">标识列ID</param>
		public bool Exists(int cid)
		{
			htSyn.Clear();
			strSql.Remove(0, strSql.Length);
			strSql.Append("select count(1) from [tab_case] where cid=@cid ");
			htSyn.Add("@cid", cid);
			return db.IsExists(strSql.ToString(), htSyn);
		}
		#endregion

		#region 得到该表数据列表
		/// <summary>
		/// 得到该表数据列表
		/// </summary>
		public IList<tab_case> GetModel()
		{
			htSyn.Clear();
			strSql.Remove(0, strSql.Length);
			strSql.Append("Select [cid],[ccid],[caseInfo],[caseDescription],[caseName],[caseTitle],[caseKey] FROM [tab_case]");
			 return gettab_caseBySql(strSql.ToString());
		}
		#endregion

		#region 根据标识列查询实体
		/// <summary>
		/// 根据标识列查询实体
		/// </summary>
		/// <param name="cid">标识列ID</param>
		/// <returns></returns>
		public tab_case GetModel(int cid)
		{
			htSyn.Clear();
			strSql.Remove(0, strSql.Length);
			strSql.Append("select [cid],[ccid],[caseInfo],[caseDescription],[caseName],[caseTitle],[caseKey] FROM [tab_case]");
			strSql.Append(" where cid=@cid ");
			htSyn.Add("@cid", cid);
			DataTable dt = db.GetDataTable(strSql.ToString(), htSyn);
			tab_case tab_caseModel = new tab_case();
			if (dt.Rows.Count > 0)
			{
				tab_caseModel.ccid=Convert.ToInt32(dt.Rows[0]["ccid"]);
				tab_caseModel.caseInfo=dt.Rows[0]["caseInfo"].ToString();
				tab_caseModel.caseDescription=dt.Rows[0]["caseDescription"].ToString();
				tab_caseModel.caseName=dt.Rows[0]["caseName"].ToString();
				tab_caseModel.caseTitle=dt.Rows[0]["caseTitle"].ToString();
				tab_caseModel.caseKey=dt.Rows[0]["caseKey"].ToString();
			}
			return tab_caseModel;
		}
		#endregion

		#region 修改信息
		/// <summary>
		/// 修改信息
		/// </summary>
		/// <param name="tab_case">实体</param>
		/// <returns></returns>
		public bool Update(tab_case tab_caseModel)
		{
			htSyn.Clear();
			strSql.Remove(0, strSql.Length);
			strSql.Append("update [tab_case] set ");
			strSql.Append("[ccid]=@ccid,");
			strSql.Append("[caseInfo]=@caseinfo,");
			strSql.Append("[caseDescription]=@casedescription,");
			strSql.Append("[caseName]=@casename,");
			strSql.Append("[caseTitle]=@casetitle,");
			strSql.Append("[caseKey]=@casekey");

			strSql.Append(" where cid=@cid ");
			htSyn.Add("@cid", tab_caseModel.cid);
			htSyn.Add("@ccid", tab_caseModel.ccid);
			htSyn.Add("@caseinfo", tab_caseModel.caseInfo);
			htSyn.Add("@casedescription", tab_caseModel.caseDescription);
			htSyn.Add("@casename", tab_caseModel.caseName);
			htSyn.Add("@casetitle", tab_caseModel.caseTitle);
			htSyn.Add("@casekey", tab_caseModel.caseKey);
			if (db.ExecuteNonQuery(strSql.ToString(), htSyn) > 0)
			{
				return true;
			}
			return false;
		}
		#endregion

		#region 删除信息
		/// <summary>
		/// 删除信息
		/// </summary>
		/// <param name="cid">标识列ID</param>
		/// <returns></returns>
		public bool Delete(int cid)
		{
			htSyn.Clear();
			strSql.Remove(0, strSql.Length);
			strSql.Append("delete from [tab_case] where cid=@cid");
			htSyn.Add("cid", cid);
			if (db.ExecuteNonQuery(strSql.ToString(), htSyn) > 0)
			{
				return true;
			}
			return false;
		}
		#endregion

		#region 添加信息
		/// <summary>
		/// 添加信息
		/// </summary>
		/// <param name="tab_case">实体</param>
		/// <returns></returns>
		public bool Insert(tab_case tab_caseModel)
		{
			htSyn.Clear();
			strSql.Remove(0, strSql.Length);
			strSql.Append("insert into [tab_case]([ccid],[caseInfo],[caseDescription],[caseName],[caseTitle],[caseKey]) values (@ccid,@caseinfo,@casedescription,@casename,@casetitle,@casekey)");
			htSyn.Add("@ccid", tab_caseModel.ccid);
			htSyn.Add("@caseinfo", tab_caseModel.caseInfo);
			htSyn.Add("@casedescription", tab_caseModel.caseDescription);
			htSyn.Add("@casename", tab_caseModel.caseName);
			htSyn.Add("@casetitle", tab_caseModel.caseTitle);
			htSyn.Add("@casekey", tab_caseModel.caseKey);
			if (db.ExecuteNonQuery(strSql.ToString(), htSyn) > 0)
			{
				return true;
			}
			return false;
		}
		#endregion

		#region 根据SQL语句获取集合
		/// <summary>
		///根据SQL语句获取集合
		/// </summary>
		/// <param name="strSql">sql语句</param>
		public IList<tab_case> gettab_caseBySql(string strSql)
		{
			IList<tab_case> list = new List<tab_case>();
			DataTable dt = db.GetDataTable(strSql);
			if (dt.Rows.Count > 0)
			{
				foreach (DataRow dr in dt.Rows)
				{
					tab_case tab_caseModel = new tab_case();
					tab_caseModel.cid= Convert.ToInt32(dr["cid"]);
					tab_caseModel.ccid= Convert.ToInt32(dr["ccid"]);
					tab_caseModel.caseInfo=dr["caseInfo"].ToString();
					tab_caseModel.caseDescription=dr["caseDescription"].ToString();
					tab_caseModel.caseName=dr["caseName"].ToString();
					tab_caseModel.caseTitle=dr["caseTitle"].ToString();
					tab_caseModel.caseKey=dr["caseKey"].ToString();
					list.Add(tab_caseModel);
				}
			}
			return list;
		}
		#endregion
	}
}
